<template>
  <van-popup v-bind="$attrs" v-on="$listeners" @close="allChecked = false">
    <section class="content">
      <header class="title">{{type}}批次信息</header>
      <section>
        <div class="name">
          {{
            selectBatchs[0].materialFields &&
            selectBatchs[0].materialFields.name
          }}
        </div>
        <div class="code">
          {{
            selectBatchs[0].materialFields &&
            selectBatchs[0].materialFields.code
          }}
        </div>
        <div class="sku" v-if="selectBatchs[0].skuName">
          <span style="color: #666666">特征参数：</span>
          {{ selectBatchs[0].skuName }}
        </div>
      </section>
      <main>
        <section
          class="batchs"
          v-for="(item, index) in selectBatchs"
          :key="index"
          @click="handleCurrent(item)"
        >
          <div class="materialQuality">
            {{ item.materialQuality ==1 ?'合格':'不合格' }}
          </div>
          <div class="batchs-t">
            <van-checkbox
              icon-size="12px"
              v-model="item.checked"
            ></van-checkbox>
            <div style="width:70%;">{{ item.barCode }}</div>
          </div>
          <div class="batchs-c">
            <!-- <div><label>仓库名称:</label>{{ item.warehouseName }}</div> -->

            <div v-if="type == '添加'"><label>库位名称:</label>{{ item.stockLocationName }}</div>
            <div class="flex">
              <div><label>可用库存:</label>{{ item.availableStock || item.count || 0}}</div>
              <div v-if="item.materialFields && item.materialFields.isDoubleUnit"><label>可用库存数(计量数):</label>{{ item.calcAvailableStock }}</div>
              
              <!-- <div><label>在库时长:</label>{{ item.stockDuration }}</div> -->
            </div>
            <!-- <div><label>生产日期:</label>{{ item.productionTime }}</div> -->
            
            <!-- <div><label>批次备注:</label>{{ item.remark }}</div> -->
          </div>
        </section>
      </main>
      <footer class="footer">
        <section @click="handleBatchClose" class="btn">取消</section>
        <section @click="submitSelectedBacths" class="btn">提交</section>
      </footer>
    </section>
  </van-popup>
</template>

<script>
export default {
  props: {
    selectBatchs: {
      type: Array,
      default: () => [],
    },
    type:{
      type: String,
      default: "",
    }
  },
  data() {
    return {
      allChecked: false,
    };
  },
  methods: {
    handleCurrent(item) {
      item.checked = !item.checked;
      this.selectBatchs.splice();
    },
    handleBatchClose(){
      this.$emit("handleBatchClose");
    },
    submitSelectedBacths() {
      const selectData = this.selectBatchs.filter((item) => item.checked);
      if (selectData.length == 0) {
        Toast("请至少选择一条数据");
        return;
      }
      this.$emit("submitFindSelectedBacths", selectData);
    },

    changeAll(val) {
      this.$emit(
        "update:selectBatchs",
        JSON.parse(JSON.stringify(this.selectBatchs)).map((batch) => ({
          ...batch,
          checked: val,
        }))
      );
    },
  },
};
</script>

<style lang="scss" scoped>
.content {
  height: 100%;
  width: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 10px;
  .title {
    text-align: center;
    height: 42px;
    font-family: Source Han Sans CN, Source Han Sans CN;
    font-weight: bold;
    font-size: 16px;
    padding: 14px 0 0 12px;
  }
  .name {
    font-family: Source Han Sans CN, Source Han Sans CN;
    font-weight: bold;
    font-size: 15px;
    color: #333333;
    margin-bottom: 5px;
  }
  .code {
    font-family: Source Han Sans CN, Source Han Sans CN;
    font-weight: 400;
    font-size: 16px;
    color: #333333;
    margin-bottom: 5px;
  }
  .sku {
    font-family: Source Han Sans CN, Source Han Sans CN;
    font-weight: 400;
    font-size: 14px;
    color: #333333;
    margin-bottom: 5px;
  }
  main {
    flex-grow: 1;
    overflow: scroll;

    .main-content {
      overflow: scroll;
      height: 300px;
    }
    .batchs {
      padding: 10px;
      background: #f5f5f5;
      border-radius: 2px 2px 2px 2px;
      margin-bottom: 5px;
      position: relative;
      .materialQuality {
        position: absolute;
        right: 20px;
        top: 10px;
        width: 42px;
        height: 18px;
        background: #e7ffe6;
        border-radius: 2px 2px 2px 2px;
        border: 1px solid #48ba47;
        display: flex;
        align-items: center;
        justify-content: center;
        font-family: Source Han Sans CN, Source Han Sans CN;
font-weight: 400;
font-size: 10px;
color: #48BA47;
      }
      .batchs-t {
        display: flex;
        align-items: center;
        font-family: Source Han Sans CN, Source Han Sans CN;
        font-weight: 500;
        font-size: 14px;
        color: #333333;
        margin-bottom: 5px;
        div {
          margin-left: 5px;
        }
      }
      .batchs-c {
        font-family: Source Han Sans CN, Source Han Sans CN;
        font-weight: 400;
        font-size: 12px;
        color: #333333;
        div {
          margin-bottom: 5px;
        }
        label {
          font-family: Source Han Sans CN, Source Han Sans CN;
          font-weight: 400;
          font-size: 12px;
          color: #666666;
        }
        .flex {
          display: flex;
          align-items: center;
          justify-content: space-between;
          flex-wrap: wrap;
          div{
            width: 50%;
          }
        }
      }
    }
  }
  footer {
    display: flex;
    align-items: center;
    height: 54px;
    width: 100%;
    .btn {
      flex-grow: 1;
      width: 90;
      height: 46px;
      background: #548af1;
      box-shadow: 0px 4px 8px 1px rgba(8, 9, 29, 0.1);
      border-radius: 4px 4px 4px 4px;
      font-size: 16px;
      font-family: Source Han Sans CN, Source Han Sans CN;
      font-weight: 400;
      color: #ffffff;
      text-align: center;
      line-height: 46px;
      &:nth-child(1){
        margin-right: 10px;
      }
    }
  }
}
</style>
